@extends('frontend/layouts/bootstrap')

@section('content')
<div>
    <span style="font-size: 31.5px;  line-height: 40px;  margin: 10px 0;  font-family: inherit;  font-weight: bold;  color: inherit;  text-rendering: optimizelegibility;  -webkit-margin-before: 0.83em;  -webkit-margin-after: 0.83em;  -webkit-margin-start: 0px;  -webkit-margin-end: 0px;"> Show Bill Detial</span>
    {{ link_to_route('car_balance.bill.index', 'Return to Bill list', null, array('class' => 'btn btn-info', 'style' => 'float: right; margin: 10px 0;')) }}
    {{ link_to_route('car_balance.bill.edit', 'Edit', $bill->id, array('class' => 'btn btn-info', 'style' => 'float: right; margin: 10px 10px;')) }}
</div>

<h4>Үндсэн мэдээлэл</h4>
<table class="table table-bordered" id="car-detail">
    <thead style="background-color: #f0f0f0;">
    <th title="Create date">Create date</th>
    <th title="Expiry date">Expiry date</th>
    <th title="Customer">Customer</th>
    <th title="Carry over amount">Carry over amount</th>
    <th title="Bill amount">Bill amount</th>
    <th title="Penalty1 amount">Tulbur udaasan penalty amount</th>
    <th title="Penalty2 amount">Auction penalty amount</th>
    <th title="Total amount">Total amount</th>
    </thead>
    <tr>
        <th>{{ $bill->create_date }}</th>
        <th>{{ $bill->expiry_date }}</th>
        <td>{{ $bill->customer ? link_to_route('car_balance.customer.show', $bill->customer->name, $bill->customer->id, array()) : 'NULL' }}</td>
        <td style="text-align: right;">{{ $bill->carry_over_amount ? number_format($bill->carry_over_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $bill->bill_amount ? number_format($bill->bill_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $bill->penalty1_amount ? number_format($bill->penalty1_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $bill->penalty2_amount ? number_format($bill->penalty2_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $bill->total_amount ? number_format($bill->total_amount, 0) : 0; }}</td>
    </tr>
</table>

@if ($cars->count())
<h4>Bill deh Car detail</h4>
<table class="table table-bordered" id="billDetailed">
    <thead style="background-color: #f0f0f0;">
    <th title="Date">日付</th>
    <th title="Auction">オーク会場</th>
    <th title="Auction no">出品番号</th>
    <th title="Car name">車種</th>
    <th title="Car year">年式</th>
    <th title="Chassis number">車体番号</th>
    <th style="text-align: center;" title="Bill price">購入額</th>
    <th style="text-align: center;" title="Vat percent">消費税</th>
    <th style="text-align: center;" title="Recycle amount">リサイクル料</th>
    <th style="text-align: center;" title="Auction commission">落札料</th>
    <th style="text-align: center;" title="Transport fee">Transport</th>
    <th style="text-align: center;" title="Vanning">Vanning</th>
    <th style="text-align: center;" title="Others">Others</th>
    <th style="text-align: center;" title="Commission">Commission</th>
    <th style="text-align: center;" title="Bill total amount">合計</th>
    <th style="text-align: center;" title="Bill sub total amount">Sub total</th>
    </thead>
    @foreach($cars as $key => $car)
    <tr>
        <td>{{ $car->purchase_date }}</td>
        <td>{{ $car->auction_name }}</td>
        <td>{{ $car->lot_no }}</td>
        <td>{{ $car->car_maker }} {{ $car->car_name }}</td>
        <td>{{ $car->car_year }}</td>
        <td>{{ $car->chasis_no }}</td>
        <td style="text-align: right;">{{ $car->bill_price ? number_format($car->bill_price, 0) : 0; }}</td>
        <td style="text-align: right;">{{ number_format(($car->bill_price*$car->bill_vat)/100, 0); }}</td>
        <td style="text-align: right;">{{ $car->bill_recycle ? number_format($car->bill_recycle, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_rakusatu ? number_format($car->bill_rakusatu, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_transport_fee ? number_format($car->bill_transport_fee, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_vanning ? number_format($car->bill_vanning, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_others ? number_format($car->bill_others, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_commission ? number_format($car->bill_commission, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_total_amount ? number_format($car->bill_total_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_sub_total_amount'][$key] ? number_format($total_bill['bill_sub_total_amount'][$key], 0) : 0; }}</td>
    </tr>
    @endforeach
    <tr>
        <td colspan="6">Total</td>
        <td style="text-align: right;">{{ $total_bill['bill_price'] ? number_format($total_bill['bill_price'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_vat'] ? number_format($total_bill['bill_vat'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_recycle'] ? number_format($total_bill['bill_recycle'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_rakusatu'] ? number_format($total_bill['bill_rakusatu'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_transport_fee'] ? number_format($total_bill['bill_transport_fee'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_vanning'] ? number_format($total_bill['bill_vanning'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_others'] ? number_format($total_bill['bill_others'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_commission'] ? number_format($total_bill['bill_commission'], 0) : 0; }}</td>
        <td style="text-align: right;">{{ $total_bill['bill_total_amount'] ? number_format($total_bill['bill_total_amount'], 0) : 0; }}</td>
        <td style="text-align: right;"></td>
    </tr>
</table>
@endif

@if ($penalties1->count())
<h4>Tulbur udaasan penalty detial</h4>
<table class="table table-bordered" id="billDetailed">
    <thead style="background-color: #f0f0f0;">
    <th title="Penalty date">Penalty date</th>
    <th title="Chassis number">車体番号</th>
    <th style="text-align: center;" title="Penalty amount">Penalty amount</th>
    </thead>
    @foreach($penalties1 as $penalty)
    <tr>
        <td>{{ $penalty->penalty_date }}</td>
        <td>{{ $penalty->chasis_no }}</td>
        <td style="text-align: right;">{{ $penalty->penalty_amount ? number_format($penalty->penalty_amount, 0) : 0; }}</td>
    </tr>
    @endforeach
    <tr>
        <td colspan="2">Total</td>
        <td style="text-align: right;">{{ $total_bill['penalty_amount1'] ? number_format($total_bill['penalty_amount1'], 0) : 0; }}</td>
    </tr>
</table>
@endif

@if ($penalties2->count())
<h4>Auction penalty detial</h4>
<table class="table table-bordered" id="billDetailed">
    <thead style="background-color: #f0f0f0;">
    <th title="Penalty date">Penalty date</th>
    <th title="Chassis number">車体番号</th>
    <th style="text-align: center;" title="Penalty amount">Penalty amount</th>
    </thead>
    @foreach($penalties2 as $penalty)
    <tr>
        <td>{{ $penalty->penalty_date }}</td>
        <td>{{ $penalty->chasis_no }}</td>
        <td style="text-align: right;">{{ $penalty->penalty_amount ? number_format($penalty->penalty_amount, 0) : 0; }}</td>
    </tr>
    @endforeach
    <tr>
        <td colspan="2">Total</td>
        <td style="text-align: right;">{{ $total_bill['penalty_amount2'] ? number_format($total_bill['penalty_amount2'], 0) : 0; }}</td>
    </tr>
</table>
@endif

@stop